<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <div th:replace="./widget/base"></div>
</head>
<body>

<div id="actReProcdefToolbar">
    <!--<a th:if="${#authorization.expression('hasRole('''+ SYSTEM_ADMIN +''') OR hasAuthority(''/COMPONENT/FLOWABLE/MAIL_EDIT_AND_SEND'')')}"-->
       <!--href="javascript:" class="easyui-linkbutton" iconCls="fa fa-reply" plain="true" onclick="mailEditAndSendDialog();">编辑重发</a>-->

    <a th:if="${#authorization.expression('hasRole('''+ SYSTEM_ADMIN +''') OR hasAuthority(''/COMPONENT/FLOWABLE/ACT_HI_PROC_DEF_DELETE_ALL'')')}"
       href="javascript:" class="easyui-linkbutton" iconCls="fa fa-close" plain="true"
       onclick="actReProcdefDeleteAll();">删除</a>

    <!--<a th:if="${#authorization.expression('hasRole('''+ SYSTEM_ADMIN +''') OR hasAuthority(''/COMPONENT/FLOWABLE/MAIL_RELOAD'')')}"-->
       <!--href="javascript:" class="easyui-linkbutton" iconCls="fa fa-refresh" plain="true" onclick="mailReload();">刷新</a>-->
</div>

<table id="actReProcdef"></table>

<script type="text/javascript">

    $(function () {
        // var SMS_STATUS = [];
        // expressui.ajax({
        //     url: Api.System.DICTIONARY + '/list_all_by_key/SMS_STATUS',
        //     async: false,
        //     success: function (data) {
        //         if (data) {
        //             SMS_STATUS = data;
        //         }
        //     }
        // });

        // var IS_OR_NOT = [];
        // expressui.ajax({
        //     url: Api.System.DICTIONARY + '/list_all_by_key/IS_OR_NOT',
        //     async: false,
        //     success: function (data) {
        //         if (data) {
        //             IS_OR_NOT = data;
        //         }
        //     }
        // });

        var columns = [
            {field: 'checkbox', checkbox: true},
            {field: 'id_', title: 'ID_'},
            {field: 'name_', title: '流程名'},
            {field: 'processDiagram', title: '流程图', formatter: function (value, row, index) {
                    return '<a href="javascript:;" onclick="viewProcessDiagramDialog(\'' + row.id_ + '\')">查看</a>';
                }
            },
            {field: 'category_', title: '分类'},
            {field: 'key_', title: 'KEY'},
            {field: 'version_', title: '版本'},
            {field: 'deploymentId_', title: '部署 ID'},
            {field: 'resourceName_', title: 'RESOURCE_NAME_'},
            {field: 'dgrmResourceName_', title: 'DGRM_RESOURCE_NAME_'},
            {field: 'description_', title: 'DESCRIPTION_'},
            {field: 'suspensionState_', title: 'SUSPENSION_STATE_'},

            // {
            //     field: 'status', title: '状态', formatter: function (value, row, index) {
            //         return expressui.grid.formatter(value, SMS_STATUS);
            //     }
            // },
            // {field: 'from', title: '发件人'},
            // {field: 'to', title: '收件人'},
            // {field: 'subject', title: '主题'},
            // {field: 'text', title: '内容'},
            // {
            //     field: 'html', title: '是否为 HTML', formatter: function (value, row, index) {
            //         return expressui.grid.formatter(value, IS_OR_NOT);
            //     }
            // },
            // {field: 'error', title: '发信报错'},
            // {field: 'remark', title: '备注'},
            // {field: 'gmtModified', title: '更新时间'},
            // {field: 'gmtCreated', title: '创建时间'}

        //
        //     id_": "holidayApplication:2:62972ce3-1d29-11e9-bf35-00e04c680090",
        // "rev_": 1,
        //     "category_": "http://www.flowable.org/processdef",
        //     "name_": "Holiday Application",
        //     "key_": "holidayApplication",
        //     "version_": 2,
        //     "deploymentId_": "60bc0440-1d29-11e9-bf35-00e04c680090",
        //     "resourceName_": "/Volumes/office/dev/IdeaProjects/nimrod/src/main/resources/processes/HolidayApplication.bpmn20.xml",
        //     "dgrmResourceName_": "/Volumes/office/dev/IdeaProjects/nimrod/src/main/resources/processes/HolidayApplication.holidayApplication.png",
        //     "description_": null,
        //     "hasStartFormKey_": 0,
        //     "hasGraphicalNotation_": "1",
        //     "suspensionState_": "1",
        //     "tenantId_": "",
        //     "engineVersion_": null,
        //     "derivedFrom_": null,
        //     "derivedFRromRoot_": null,
        //     "derivedVersion_"
        ];

        $('#actReProcdef').datagrid(expressui.grid.create, {
            title: '流程定义',
            url: Api.Flowable.ACT_RE_PROCDEF + '/page_all',
            columns: [columns],
            idField: 'id_',

        });
    });

    function mailEditAndSendDialog() {
        var one = $('#actReProcdef').datagrid(expressui.grid.getCheckedOneShowAlert);
        if (one) {
            $('#actReProcdefEditAndSendDialog').dialog(expressui.dialog.create, {
                title: '编辑重发',
                grid: {type: 'datagrid', selector: '#actReProcdef'},
                href: Page.System.MAIL + '/edit_and_send_dialog',
                get: {url: Api.System.MAIL + '/one/{id}', method: 'get'},
                save: {url: Api.System.MAIL + '/add_one', method: 'post'},
                buttons: [{
                    text: '发送',
                    iconCls: 'fa fa-save',
                    handler: expressui.dialog.save,
                    reload: [{type: 'datagrid', selector: '#actReProcdef'}],
                    success: '操作成功'
                }, {
                    text: '关闭',
                    iconCls: 'fa fa-close',
                    handler: expressui.dialog.close
                }]
            });
        }
    }

    function mailReload() {
        expressui.grid.reload({type: 'datagrid', selector: '#actReProcdef'})
    }

    function actReProcdefDeleteAll() {
        $('#actReProcdef').datagrid(expressui.grid.deleteRows, {
            url: Api.Flowable.ACT_RE_PROCDEF + '/delete_all',
            method: 'post',
            success: '删除成功',
            reload: [{type: 'datagrid', selector: '#actReProcdef'}],
        });

            //
            // $('#actReProcdefDeleteAllDialog').dialog(expressui.dialog.create, {
            //     title: '删除',
            //     // grid: {type: 'datagrid', selector: '#actReProcdef'},
            //     href: Page.Flowable.ACT_RE_PROCDEF + '/delete_dialog_dialog',
            //     // get: {url: Api.System.MAIL + '/one/{id}', method: 'get'},
            //     save: {url: Api.Flowable.ACT_RE_PROCDEF + '/delete_all', method: 'post'},
            //     buttons: [{
            //         text: '确定',
            //         iconCls: 'fa fa-ok',
            //         handler: expressui.dialog.save,
            //         reload: [{type: 'datagrid', selector: '#actReProcdef'}],
            //         success: '操作成功'
            //     }, {
            //         text: '关闭',
            //         iconCls: 'fa fa-close',
            //         handler: expressui.dialog.close
            //     }]
            // });

    }

    function viewProcessDiagramDialog(processDefinitionId) {
        $('#viewProcessDiagramDialog').dialog(expressui.dialog.create, {
            title: '流程图',
            width:800,
            height:500,
            content: '<img src="' + Api.Flowable.ACT_RE_PROCDEF + '/process_diagram?processDefinitionId=' + processDefinitionId + '">',
            buttons: [{
                text: '关闭',
                iconCls: 'fa fa-close',
                handler: expressui.dialog.close
            }]
        });

    }

</script>

</body>
</html>